package com.lzdongrui.backend.service.impl;

import java.util.List;

import com.lzdongrui.backend.domain.dto.InstructorDTO;
import com.lzdongrui.backend.domain.vo.InstructorVO;
import com.lzdongrui.common.utils.snowid.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lzdongrui.backend.mapper.InstructorMapper;
import com.lzdongrui.backend.domain.Instructor;
import com.lzdongrui.backend.service.IInstructorService;

/**
 * 辅导员Service业务层处理
 * 
 * @author wyh
 * @date 2023-05-19
 */
@Service
public class InstructorServiceImpl implements IInstructorService 
{
    @Autowired
    private InstructorMapper instructorMapper;

    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;

    /**
     * 查询辅导员
     * 
     * @param id 辅导员主键
     * @return 辅导员
     */
    @Override
    public Instructor selectInstructorById(Long id)
    {
        return instructorMapper.selectInstructorById(id);
    }

    /**
     * 查询辅导员列表
     * 
     * @param instructorDTO 辅导员
     * @return 辅导员
     */
    @Override
    public List<InstructorVO> selectInstructorList(InstructorDTO instructorDTO)
    {
        return instructorMapper.selectInstructorList(instructorDTO);
    }

    /**
     * 新增辅导员
     * 
     * @param instructor 辅导员
     * @return 结果
     */
    @Override
    public int insertInstructor(Instructor instructor)
    {
        instructor.setId(snowflakeIdWorker.nextId());
        return instructorMapper.insertInstructor(instructor);
    }

    /**
     * 修改辅导员
     * 
     * @param instructor 辅导员
     * @return 结果
     */
    @Override
    public int updateInstructor(Instructor instructor)
    {
        return instructorMapper.updateInstructor(instructor);
    }

    /**
     * 批量删除辅导员
     * 
     * @param ids 需要删除的辅导员主键
     * @return 结果
     */
    @Override
    public int deleteInstructorByIds(Long[] ids)
    {
        return instructorMapper.deleteInstructorByIds(ids);
    }

    /**
     * 删除辅导员信息
     * 
     * @param id 辅导员主键
     * @return 结果
     */
    @Override
    public int deleteInstructorById(Long id)
    {
        return instructorMapper.deleteInstructorById(id);
    }

    @Override
    public int moreEdit(Long[] ids, Long instructor, Long operator) {
        int ret = 0;
        for (int i = 0; i<ids.length;i++){
            Instructor instructor1 = new Instructor();
            instructor1.setId(ids[i]);
            instructor1.setInstructor(instructor);
            instructor1.setOperator(operator);
            ret =  instructorMapper.moreEdit(instructor1);
        }
        return ret;
    }

    @Override
    public int moreAdd(Long[] ids, Long instructor, Long operator) {
        int ret = 0;
        for (int i = 0; i<ids.length;i++){
            Instructor instructor1 = new Instructor();
            instructor1.setId(snowflakeIdWorker.nextId());
            instructor1.setGradeId(ids[i]);
            instructor1.setInstructor(instructor);
            instructor1.setOperator(operator);
            ret =  instructorMapper.moreAdd(instructor1);
        }
        return ret;
    }
}
